import React from 'react';

import BaseAction from '../common/BaseAction';
import Constants from '../../common/Constants';
import ResponseConstants from '../../common/ResponseConstants';

//type (integer): 使用类型，1登录，2注册 = ['1', '2']
export default class RequestSmsAction extends BaseAction {
  constructor() {
    super();

    this.moduleType = Constants.MODULE_TYPE.LOGIN;
    this.name = "RequestSmsAction";
  }

  call(caller, data) {
    this._baseCall(caller, data);
    this.caller.setState({
      viewStatus: 2,
    })
  }

  finish(data, isSucceed, response) {
    let status = response.status;
    let detail = "错误";
    if(isSucceed) {
      if(response.status == ResponseConstants.status_created_success) {
        status = ResponseConstants.status_sms_success;
      }
      else if(response.status == ResponseConstants.status_unauthorized) {
        detail = data.detail;
      }
      else if(response.status == ResponseConstants.status_conflict) {
        detail = "请求太频繁或者超过每日10条限制";
      }
      else {
        detail = "未知错误";
      }
    }
    else {
      status = -100;
    }
    this.caller.setState({
      viewStatus: status,
      statusText: detail,
    })
  }
}
